<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">文章管理</div>
                        </div>
                        <div class="widget-body  am-fr">


                            <!--筛选搜索-->
                            <form action=""></form>

                            <form id="searchform" action="{:Url('search')}"  method="post" >
                                <table class="table">
                                    <tbody>
                                    <td  class="col-sm-3">
                                        <input type="text" class="form-control" value="{$Think.get.consignee}" placeholder="搜索" name="consignee">
                                    </td>
                                    <td  class="col-sm-2">
                                        <select class="form-control input-sm" name="shipping_status">
                                            <option value="0">选择文章类别</option>
                                            {foreach name="category" key="key" item="v"}
                                            <option value="{$v.cat_id}" {if $Think.get.shipping_status eq $v.cat_id}selected="selected"{/if}>{$v.cat_name}</option>
                                        {/foreach}
                                        </select>
                                    </td>
                                    <td>
                                    <div class="col-sm-12">
                                        <button class="btn btn-primary" type="submit" >搜索</button>
                                        <a href="{:url('article_list')}"><button type="button" id="loading-example-btn" class="btn btn-white btn-sm"><i class="fa fa-refresh"></i> 刷新</button></a>
                                    </div>
                                    </td>
                                    <td>
                                        <div class="form-group pull-right">
                                            <a href="{:url('article_add')}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加文章</a>
                                        </div>
                                    </td>
                                    </tbody>
                                </table>
                            </form>
                            <div class="am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                    <thead>
                                    <tr>

                                        <th>文章标题</th>
                                        <th>文章类别</th>
                                        <th>描述</th>
                                        <th>显示</th>
                                        <th>发布时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {foreach name="list" key="key" item="v"}
                                    <tr class="gradeX">
                                        <td>{$v.title}</td>
                                        <td>{$v.cat_name}</td>
                                        <td>{$v.keywords}</td>
                                        <td>
                                            {if $v.is_open eq 1}
                                            <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" masterid='{$v.article_id}'><i class="fa fa-check" ></i>&nbsp;显示</button>
                                            {else}
                                            <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" masterid='{$v.article_id}' ><i class="fa fa-times" ></i>
                                                <span class="bold" >禁用</span>
                                            </button>
                                            {/if}
                                        </td>
                                        <td>{$v.add_time|date='Y-m-d H:i:s',###}</td>
                                        <td>
                                            <div class="tpl-table-black-operation">
                                                <a href="{:Url('article_edit')}?article_id={$v.article_id}">
                                                    <i class="am-icon-pencil"></i> 编辑
                                                </a>
                                                <a onclick="del_button('{$v.article_id}','{$v.thumb}');" href="javascript:void(0);" href="javascript:;" class="tpl-table-black-operation-del">
                                                    <i class="fa fa-trash-o"></i> 删除
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    <!-- more data -->
                                    </tbody>
                                </table>
                            </div>
                            <div class="am-u-lg-10 am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        {$list->render()}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
<link href="/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css">
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>
    // 删除按钮
    function del_button(id, thumb) {
        layer.confirm("确定删除？", {btn: ["确定","取消"], shade: 0.5}, function(){
            // 删除权限组
            $.post("{:url('del')}", {id: id,thumb:thumb}, function(res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }

                layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 1}, function() {
                    layer.closeAll('page');
                    location.reload();
                });
            });
        }, function () {});
    }

    //提交
    function roleSubmit() {
        var form = document.getElementById("searchform");
        var formData = new FormData(form);
        $.ajax({
            url: "{:Url('index')}",
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success: function (res) {
                console.log(res);
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function () {
                    window.location.href = document.referrer;

                });
            }
        })
    }

    //选择时间js
    $(document).ready(function() {
        $('#start_time').daterangepicker({
            format:"YYYY-MM-DD",
            singleDatePicker: false,
            showDropdowns: true,
            minDate:'2016-01-01',
            maxDate:'2030-01-01',
            startDate:'2016-01-01',
            showWeekNumbers: true,
            timePicker: false,
            timePickerIncrement: 1,
            timePicker12Hour: true,
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
                '最近7天': [moment().subtract('days', 6), moment()],
                '最近30天': [moment().subtract('days', 29), moment()],
                '上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
            },
            opens: 'right',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary',
            cancelClass: 'btn-small',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });
    });

    // 启用禁用修改
    function changedisable(e,d){
        article_id      = $(e).attr('masterid');
        is_open = $(e).attr('data-val');

        // 状态修改
        $.post("{:url('change')}", {article_id: article_id, is_open: is_open}, function(ret){
            if(ret.code != 200){
                layer.tips(ret.msg, e, {tips: [4, 'red']});
            }

            layer.msg(ret.msg, {time: 2000, shift: 4}, function(){
                if(is_open == 0) {
                    $(e).toggleClass('btn-default');
                    $(e).toggleClass('btn-primary');
                    $(e).html("<i class='fa fa-times'></i> <span class='bold'>禁用</span>");
                    $(e).attr('data-val','1');
                    return false;
                }

                $(e).toggleClass('btn-default');
                $(e).toggleClass('btn-primary');
                $(e).html("<i class='fa fa-check'></i>&nbsp;显示");
                $(e).attr('data-val','0');
                return false;
            });
        });
    }
</script>
</html>